package c_admin
import (
	"gintest/models"
	"gintest/until"
	"github.com/gin-gonic/gin"
	"strconv"
	"strings"
)

func Order_list(c *gin.Context){
	page,_:=strconv.ParseUint(c.DefaultPostForm("page","1"),10,64)
	pagesize,_:=strconv.ParseUint(c.DefaultPostForm("limit","15"),10,64)
	status,_:=strconv.ParseUint(c.DefaultPostForm("status","0"),10,64)
	pay,_:=strconv.ParseUint(c.DefaultPostForm("pay","0"),10,64)

	start:=c.DefaultPostForm("start","")
	end:=c.DefaultPostForm("end","")
	keyword:=c.DefaultPostForm("keyword","")
	area:=c.DefaultPostForm("area","")
	list,total:=models.GetOrderList(page,pagesize,status,pay,start,end,keyword,area)
	until.Success(c,map[string]interface{}{"data":list,"total":total})
}
func Order_detail(c *gin.Context){
	id:=c.DefaultPostForm("id","")
	if len(id)==0{
		until.Fail(c,1,"id field cannot be empty")
		return
	}

	aid,_:=strconv.Atoi(id)
	data:=models.GetOrderById(aid)
	until.Success(c,data)

}
func Order_del(c *gin.Context){
	idsstr:=c.DefaultPostForm("id","")
	idsstr_arr := strings.Split(idsstr, ",")
	var ids []int
	for i:=0;i<len(idsstr_arr);i++{
		intt,_:=strconv.Atoi(idsstr_arr[i])
		ids=append(ids,intt)
	}
	if err:=models.DelOrderByIds(ids);err != nil{
		until.Fail(c,1,err.Error())
		return
	}
	until.Success(c,nil)
}